package com.distributer.gateway.hander;

import com.distributer.gateway.model.RequestContext;

/**
 * 业务任务
 * @author xiaolin
 *
 */
public abstract class BusinessTask implements Runnable{

	private final RequestContext requestContext;
	
	public BusinessTask(RequestContext requestContext) {
		this.requestContext = requestContext;
	}

	@Override
	public void run() {
		try {
			businessExecute(requestContext);
		} catch (Throwable throwable) {
			errorExecute(throwable);
		}
	}
	
	/**
	 * 具体执行业务的方法
	 * @param requestContext
	 */
	public abstract void businessExecute(RequestContext requestContext);
	
	/**
	 * 异常处理
	 * @param throwable
	 */
	public abstract void errorExecute(Throwable throwable);
	
	public String getServiceName(){
		return requestContext.getEurakaServiceName();
	}
	
	
	public RequestContext getRequestContext() {
		return requestContext;
	}
}
